#include"Engine.h"

Texture::Texture(){
	texture = NULL;	
}

Texture::~Texture(){
	release();
}

bool Texture::load(std::string filename, D3DCOLOR transcolor){
	HRESULT result;

	//lay thong tin chieu dai va rong cua file bitmap 
	result = D3DXGetImageInfoFromFile( filename.c_str(), &info );
	if(result != D3D_OK){
		texture = NULL;
		return false;
	}
	//khoi tao mot texture tu viec load file bitmap
	result = D3DXCreateTextureFromFileEx( g_engine->getDevice(),
										  filename.c_str(),
										  info.Width,
										  info.Height,
										  1,
										  D3DPOOL_DEFAULT,
										  D3DFMT_UNKNOWN,
										  D3DPOOL_DEFAULT,
										  D3DX_DEFAULT,
										  D3DX_DEFAULT,
										  transcolor,
										  &info,
										  NULL,
										  &texture);
	if( result != D3D_OK){
		texture = NULL;
		return false;
	}
	return true;
}

void Texture::release(){
	if(texture) texture->Release();
}